home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / beav_132 / part01 / tcap.c < prev    next >
C/C++ Source or Header  |  1991-11-13  |  3KB  |  167 lines

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for beav
  3. */
  4.  
  5. #include "def.h"
  6.  
  7. #ifdef UNIX
  8.  
  9. #define    MARGIN    8
  10. #define    SCRSIZ    64
  11. #define    NPAUSE    10            /* # times thru update to pause */
  12. #define BEL     0x07
  13. #define ESC     0x1B
  14.  
  15. extern char     *tgoto();
  16.  
  17. #ifdef NOPROTO
  18. extern int      ttputc();
  19. void    putpad();
  20. #endif
  21.  
  22. #ifdef    COLOR
  23. extern int        tcapfcol();
  24. extern int        tcapbcol();
  25. #endif
  26.  
  27. #define TCAPSLEN 315
  28. char tcapbuf[TCAPSLEN];
  29. char *UP, PC, *CM, *CE, *CL, *SO, *SE;
  30.  
  31. #ifdef BSD
  32. #include <sys/ioctl.h>
  33. struct ttysize ttysize;
  34. #endif /* BSD */
  35. #ifdef ULTRIX
  36. struct ttysize ttysize;
  37. #endif
  38.  
  39. void    putpad(str)
  40. char    *str;
  41. {
  42.     tputs(str, 1, ttputc);
  43. }
  44.  
  45. void    tcapopen()
  46. {
  47.     char *getenv();
  48.     char *t, *p, *tgetstr();
  49.     char tcbuf[1024];
  50.     char *tv_stype;
  51.     char err_str[NCOL];
  52. #ifdef ULTRIX
  53.     struct winsize ttysize;
  54. #endif
  55.  
  56.     if ((tv_stype = getenv("TERM")) == NULL)
  57.     {
  58.         puts("Environment variable TERM not defined!\r");
  59.         ttclose();
  60.         exit(1);
  61.     }
  62.  
  63.     if ((tgetent(tcbuf, tv_stype)) != 1)
  64.     {
  65.         sprintf(err_str, "Unknown terminal type %s!\r", tv_stype);
  66.         puts(err_str);
  67.         ttclose();    /* fix in 1.13 */
  68.         exit(1);
  69.     }
  70.  
  71.  
  72. #ifdef BSD 
  73. #ifdef ULTRIX
  74.     if (ioctl(0, TIOCGWINSZ, &ttysize) == 0
  75.         && ttysize.ws_row > 0) {
  76.         nrow = ttysize.ws_row;
  77.     } else
  78. #else
  79.         if (ioctl(0, TIOCGSIZE, &ttysize) == 0
  80.             && ttysize.ts_lines > 0) {
  81.             nrow = ttysize.ts_lines;
  82.         }
  83.         else
  84. #endif /* ULTRIX */
  85. #endif /* BSD */
  86.             if ((nrow=(short)tgetnum("li")-1) == -1){
  87.                 puts("termcap entry incomplete (lines)\r");
  88.                 ttclose();    /* fix in 1.13 */
  89.                 exit(1);
  90.             }
  91.     printf ("nrow %d, ncol %d\n", nrow, ncol);
  92.     /* don't allow to specify a larger number of rows than we can handle 1.13 */
  93.     if (nrow > NROW)
  94.         nrow = NROW;
  95.  
  96.     if ((ncol=(short)tgetnum("co")) == -1){
  97.         puts("Termcap entry incomplete (columns)\r");
  98.         ttclose();    /* fix in 1.13 */
  99.         exit(1);
  100.     }
  101.     /* don't allow to specify a larger number of cols than we can handle 1.13 */
  102.     if (ncol > NCOL)
  103.         ncol = NCOL;
  104.  
  105.     p = tcapbuf;
  106.     t = tgetstr("pc", &p);
  107.     if(t)
  108.         PC = *t;
  109.  
  110.     CL = tgetstr("cl", &p);
  111.     CM = tgetstr("cm", &p);
  112.     CE = tgetstr("ce", &p);
  113.     UP = tgetstr("up", &p);
  114.     SE = tgetstr("se", &p);
  115.     SO = tgetstr("so", &p);
  116.  
  117.     if(CL == NULL || CM == NULL || UP == NULL)
  118.     {
  119.         puts("Incomplete termcap entry\r");
  120.         ttclose();    /* fix in 1.13 */
  121.         exit(1);
  122.     }
  123.  
  124.     if (p >= &tcapbuf[TCAPSLEN])
  125.     {
  126.         puts("Terminal description too big!\r");
  127.         ttclose();    /* fix in 1.13 */
  128.         exit(1);
  129.     }
  130. }
  131.  
  132. void    tcapmove(row, col)
  133. register int row, col;
  134. {
  135.     putpad(tgoto(CM, col, row));
  136. }
  137.  
  138. void    tcapeeol()
  139. {
  140.     putpad(CE);
  141. }
  142.  
  143. void    tcapeeop()
  144. {
  145.     putpad(CL);
  146. }
  147.  
  148. void    tcaprev(state)        /* change reverse video status */
  149. int state;        /* FALSE = normal video, TRUE = reverse video */
  150.  
  151. {
  152.     if (state) {
  153.         if (SO != NULL)
  154.             putpad(SO);
  155.     } else
  156.         if (SE != NULL)
  157.             putpad(SE);
  158. }
  159.  
  160. void    putnpad(str, n)
  161. char    *str;
  162. {
  163.     tputs(str, n, ttputc);
  164. }
  165.  
  166. #endif
  167.